import urllib2
import re
from urlparse import urlparse

def get_bars():
    bars = {}
    opener = urllib2.build_opener()
    for i in range(1,20):
        openfile = opener.open('http://www.newyorkontap.com/showresults.asp?hood=1&page=' + str(i))        
        urlPatter = re.compile('(&from=search">)((\w+).)*(</a></div>)')

        for line in openfile.readlines():
            m = urlPatter.search(line)
            if m:
                x = m.group()
                bars[x] = x
                print x
        f = open('bars.txt','w')
        for k, v in bars.items():
            f.write(str(k) + '\n')
        f.close()
    print 'Done!'

get_bars()
